package com.jd.nbd.strategy05;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by liyue on 2017/8/24
 */
public class Client {
  public static void main(String[] args) {
    //准备数据
    Context context = new Context();
    List<Person> personList = new ArrayList<Person>();
    Person noNamePerson = new Person();
    noNamePerson.setName("");
    personList.add(noNamePerson);
    for (int i = 1; i < 100; i++) {
      Person person = new Person();
      person.setAge(i);
      person.setGender(i%2);
      person.setName("张" + i);
      person.setHealth(i);
      personList.add(person);
    }



    for (Person person : personList) {
      //System.out.println("person = " + person);
      //校验逻辑
      int age = person.getAge();

      if (0 < age && age <= 10) {
        context.setRuleList(RuleFactory.getRules(0));
      } else if (10 < age && age <= 20) {
        context.setRuleList(RuleFactory.getRules(1));
      } else if (20 < age && age <= 60) {
        context.setRuleList(RuleFactory.getRules(2));
      } else {
        context.setRuleList(RuleFactory.getRules(3));
      }
      boolean validateResult = context.doValidate(person);

      System.out.println(person + " validateResult = " + validateResult);
    }
  }


}
